package com.cynteka.cyfoman.ui.collection;

import com.cynteka.cyfoman.core.config.ColumnMD;
import org.jdesktop.swingx.treetable.TreeTableModel;

import java.util.List;

/**
 * User: Sergey
 * Date: 02.08.11
 * Time: 0:39
 */
public class CollectionTreeTableModel extends CollectionTreeModel implements TreeTableModel {

    private List<ColumnMD> columns;

    @Override
    public Class<?> getColumnClass(int i) {
        return columns.get(i).getColumnClass();
    }

    @Override
    public int getColumnCount() {
        return columns.size();
    }

    @Override
    public String getColumnName(int i) {
        return columns.get(i).getTitle();
    }

    @Override
    public int getHierarchicalColumn() {
        return 0;
    }

    @Override
    public Object getValueAt(Object o, int i) {
        ColumnMD column = columns.get(i);
        Pair p = (Pair) o;
        Object value = getPropertyResolver().getProperty(p.value, column.getName());
        return value;
    }

    @Override
    public boolean isCellEditable(Object o, int i) {
        return false;
    }

    @Override
    public void setValueAt(Object o, Object o1, int i) {
    }

    public List<ColumnMD> getColumns() {
        return columns;
    }

    public void setColumns(List<ColumnMD> columns) {
        this.columns = columns;
    }
}
